package com.ruoyi.web.controller.retirement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.retirement.domain.RetirementMenu;
import com.ruoyi.retirement.service.IRetirementMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页菜单/一级分类Controller
 * 
 * @author 曹旭
 * @date 2025-09-01
 */
@RestController
@RequestMapping("/retirement/retirementMenu")
public class RetirementMenuController extends BaseController
{
    @Autowired
    private IRetirementMenuService retirementMenuService;


    /**
     * 查询首页菜单/一级分类列表
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:list')")
    @GetMapping("/page")
    public TableDataInfo page(RetirementMenu retirementMenu)
    {
        /* 如果需要部门权限把这里打开 */
        /*if (!isAdmin()){
            retirementMenu.setDeptId(SecurityUtils.getLoginUser().getDeptId().toString());
        }*/
        startPage();
        List<RetirementMenu> list = retirementMenuService.selectRetirementMenuList(retirementMenu);
        return getDataTable(list);
    }

    /**
     * 查询首页菜单/一级分类列表
     */
    @GetMapping("/list")
    public AjaxResult list(RetirementMenu retirementMenu)
    {
        List<RetirementMenu> list = retirementMenuService.selectRetirementMenuList(retirementMenu);
        return success(list);
    }

    /**
     * 导出首页菜单/一级分类列表
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:export')")
    @Log(title = "首页菜单/一级分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RetirementMenu retirementMenu)
    {
        List<RetirementMenu> list = retirementMenuService.selectRetirementMenuList(retirementMenu);
        ExcelUtil<RetirementMenu> util = new ExcelUtil<RetirementMenu>(RetirementMenu.class);
        util.exportExcel(response, list, "首页菜单/一级分类数据");
    }

    /**
     * 获取首页菜单/一级分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(retirementMenuService.selectRetirementMenuById(id));
    }

    /**
     * 新增首页菜单/一级分类
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:add')")
    @Log(title = "首页菜单/一级分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RetirementMenu retirementMenu)
    {
        return toAjax(retirementMenuService.insertRetirementMenu(retirementMenu));
    }

    /**
     * 修改首页菜单/一级分类
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:edit')")
    @Log(title = "首页菜单/一级分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RetirementMenu retirementMenu)
    {
        return toAjax(retirementMenuService.updateRetirementMenu(retirementMenu));
    }

    /**
     * 删除首页菜单/一级分类
     */
    @PreAuthorize("@ss.hasPermi('retirement:retirementMenu:remove')")
    @Log(title = "首页菜单/一级分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(retirementMenuService.deleteRetirementMenuByIds(ids));
    }
}
